#!/bin/bash
#clickhouse-client -h 192.168.10.42 --port 9000 -u xm --password GQ_URkcstoBT

OUTDIR=/root/backup/
 
clickhouse-client -h 192.168.10.42 --port 9000 -u xm --password GQ_URkcstoBT  -q "SHOW DATABASES" > /root/backup/db.txt
while read -r db 
do
        clickhouse-client -h 192.168.10.42 --port 9000 -u xm --password GQ_URkcstoBT -q "SHOW TABLES FROM xm" > /root/backup/table.txt
        while read -r table
        do

                echo "export table $table from database $db"
 
                # dump schema
                clickhouse-client -h 192.168.10.42 --port 9000 -u xm --password GQ_URkcstoBT -q "SHOW CREATE TABLE ${db}.${table} format CSV" >> "${OUTDIR}/schema.sql"
 
 
  done  < `ls /root/backup/table.txt`
done  < `ls /root/backup/db.txt`

